package com.cy.cuiyang_admin.util;
import com.cy.cuiyang_admin.pojo.UserInfo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Copyright (C), 2008-2020, 国家电网公司客户服务中心信息运维中心
 * Project:  wxws
 *
 * @author: bingdor
 * Date:     2020/7/22 2:14 下午
 * Description: //模块目的、功能描述
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
public class SessionUtil {
    public static final String SESSION_CNT_USER_KEY = "SESSION_CNT_USER_KEY";

    /**
     * 获取当前用户信息
     *
     * @param request
     * @return
     */
    public static UserInfo getCurrentUser(HttpServletRequest request) {
        HttpSession session = request.getSession(true);
        Object attribute = session.getAttribute(SESSION_CNT_USER_KEY);
        if (attribute != null && attribute instanceof UserInfo) {
            return (UserInfo) attribute;
        }
        return null;
    }

    /**
     * 设置当前用户
     * @param request
     * @param userInfo
     */
    public static void setCurrentUser(HttpServletRequest request, UserInfo userInfo) {
        HttpSession session = request.getSession(true);
        session.setAttribute(SESSION_CNT_USER_KEY, userInfo);
    }
}
